package com.neusoft.movie.v_movies.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.neusoft.movie.v_movies.R;
import com.neusoft.movie.v_movies.common.Constants;
import com.neusoft.movie.v_movies.javabean.ActivityBean;
import com.neusoft.movie.v_movies.javabean.EnterBean;
import com.neusoft.movie.v_movies.listener.RetrofitListener;
import com.neusoft.movie.v_movies.model.ActivityModel;
import com.neusoft.movie.v_movies.model.UsersModel;
import com.squareup.picasso.Picasso;

import static com.neusoft.movie.v_movies.common.Constants.PHOTO_URL;

public class MyEnterActInfoActivity extends BaseActivity implements RetrofitListener {

    private TextView e_name,e_email,e_address,e_remarks,e_fb,act_name;
    private ImageView act_pic,left;
    private int act_id;
    private Context mContext;
    private int u_id;


    @Override
    void initViews() {
        setLayout(R.layout.activity_my_enter_act_info);
        act_name= (TextView) findViewById(R.id.act_name);
        e_name = (TextView) findViewById(R.id.e_name);
        act_pic = (ImageView) findViewById(R.id.act_pic);
        e_email = (TextView) findViewById(R.id.e_email);
        e_address = (TextView) findViewById(R.id.e_address);
        e_remarks = (TextView) findViewById(R.id.e_remarks);
        e_fb = (TextView) findViewById(R.id.e_fb);
        left=(ImageView) findViewById(R.id.left_button);

    }

    @Override
    void initData() {
        Bundle bundle = this.getIntent().getExtras();
        act_id = bundle.getInt("act_id");

        SharedPreferences sharedPreferences=getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        u_id=sharedPreferences.getInt("u_id",0);

        getMyActOrderdetail();
        getDetail();

    }
    void getMyActOrderdetail()
    {
        UsersModel usersModel = new UsersModel();
        usersModel.getMyActOrderdetail(u_id,act_id,this);
    }
    void getDetail()
    {
        ActivityModel activityModel = new ActivityModel();
        activityModel.getDetail(act_id,this);
    }

    @Override
    void initEvents() {
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public void onSuccess(Object o, int flag) {
        switch(flag){
            case Constants.GETMYENTERACTDETAIL:
                EnterBean enterBean=(EnterBean) o;
                e_name.setText(enterBean.getE_name());
                e_address.setText(enterBean.getE_address());
                e_email.setText(enterBean.getE_email());
                e_remarks.setText(enterBean.getE_remarks());
               // e_fb.setText(enterBean.getE_fb());
                if("".equals(enterBean.getE_fb())){
                    e_fb.setText("很抱歉，报名失败");
                }
                else {
                    e_fb.setText(enterBean.getE_fb());
                }
                break;

            case Constants.GETACTIVITYDETAIL:
                ActivityBean activityBean=(ActivityBean) o;
                String pic = PHOTO_URL+activityBean.getAct_pic();
                if(!activityBean.getAct_pic().equals("")){
                    Picasso.with(mContext).load(pic).into(act_pic);
                }
                act_name.setText(activityBean.getAct_name());
                break;
        }
    }

    @Override
    public void onFailed() {
        Toast.makeText(MyEnterActInfoActivity.this, "操作失败", Toast.LENGTH_SHORT).show();
    }
}
